package com.rose.springbootwebsocket.config;

import com.rose.springbootwebsocket.service.WebSocketTestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

/**
 * 配置viewController,为页面提供路径映射
 */
@Controller
@RequestMapping("/webSocket")
public class WebMvcConfig {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private Environment env;
    @Autowired
    private WebSocketTestService webSocketTestService;
    @RequestMapping("/jxl")
    public String webSocket(Model model) {
        try {
            model.addAttribute("ip", IpAddressUtils.getInternetIp());
            model.addAttribute("host", env.getProperty("server.port"));

            Class<? extends WebSocketTestService> aClass = webSocketTestService.getClass();
            Method[] methods = aClass.getDeclaredMethods();
            List<String> methodList=new ArrayList<>();
            for (Method s:methods){
                methodList.add(s.getName());
            }
            model.addAttribute("methods", methodList);
        } catch (Exception e) {
            logger.error("获取ip端口错误-e:{}", e);
        }
        return "jxl_socket";
    }


}


